package com.xbts.web.controller.cloud;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xbts.common.utils.SecurityUtils;
import com.xbts.system.domain.vo.CnWorkOrderDetailVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnWorkOrderDetail;
import com.xbts.system.service.ICnWorkOrderDetailService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 工单详细Controller
 * @author xbts
 * @date 2023-08-28
 */
@Api("工单详细")
@RestController
@RequestMapping("/system/order/detail")
public class CnWorkOrderDetailController extends BaseController {

    @Autowired
    private ICnWorkOrderDetailService cnWorkOrderDetailService;

    /**
     * 查询工单详细列表
     */
    @ApiOperation("查询工单详细列表")
    @PreAuthorize("@ss.hasPermi('system:detail:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnWorkOrderDetail cnWorkOrderDetail) {
        startPage(cnWorkOrderDetail);
        List<CnWorkOrderDetailVO> list = cnWorkOrderDetailService.selectCnWorkOrderDetailList(cnWorkOrderDetail);
        return getDataTable(list);
    }

    /**
     * 获取站内消息 详细信息
     */
    @GetMapping(value = "/getUnreadNum")
    public AjaxResult getUnreadNum() {
        long count = cnWorkOrderDetailService.getUnreadNum();
        return AjaxResult.success(count);
    }

    /**
     * 导出工单详细列表
     */
    @ApiOperation("导出工单详细列表")
    @PreAuthorize("@ss.hasPermi('system:detail:export')")
    @Log(title = "工单详细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnWorkOrderDetail cnWorkOrderDetail) {
        List<CnWorkOrderDetailVO> list = cnWorkOrderDetailService.selectCnWorkOrderDetailList(cnWorkOrderDetail);
        ExcelUtil<CnWorkOrderDetailVO> util = new ExcelUtil<>(CnWorkOrderDetailVO.class);
        util.exportExcel(response, list, "工单详细数据");
    }

    /**
     * 获取工单详细详细信息
     */
    @ApiOperation("获取工单详细详细信息")
    @ApiImplicitParam(name = "id", value = "工单详细ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(cnWorkOrderDetailService.selectCnWorkOrderDetailById(id));
    }

    /**
     * 新增工单详细（留言）
     */
    @ApiOperation("新增工单详细（留言）")
    @PreAuthorize("@ss.hasPermi('system:detail:add')")
    @Log(title = "工单详细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CnWorkOrderDetail cnWorkOrderDetail) {
        return toAjax(cnWorkOrderDetailService.insertCnWorkOrderDetail(cnWorkOrderDetail));
    }

    /**
     * 修改工单详细
     */
    @ApiOperation("修改工单详细")
    @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "工单详细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnWorkOrderDetail cnWorkOrderDetail) {
        return toAjax(cnWorkOrderDetailService.updateCnWorkOrderDetail(cnWorkOrderDetail));
    }
    /**
     * 工单留言已读
     */
    @ApiOperation("工单留言已读")
    @PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "工单留言已读", businessType = BusinessType.UPDATE)
    @PutMapping("read")
    public AjaxResult read(@RequestBody List<String> ids) {
        return toAjax(cnWorkOrderDetailService.read(ids));
    }

    /**
     * 删除工单详细
     */
    @ApiOperation("删除工单详细")
    @ApiImplicitParam(name = "ids", value = "工单详细ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:detail:remove')")
    @Log(title = "工单详细", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> ids) {
        return toAjax(cnWorkOrderDetailService.deleteCnWorkOrderDetailByIds(ids));
    }
}
